package com.tenghu.sbm.rest;

import java.util.Map;

/**
 * 消息响应工厂类
 * @author Arvin
 * @date 2017/12/9 14:26
 */
public class RestResponseFactory {
    private RestResponseFactory(){}

    public static RestResponse getSucResponse(String message){
        return buildResponse(message);
    }

    public static RestResponse getSucResponse(Map<String,Object> data){
        return getResponse().setData(data);
    }

    public static RestResponse getSucResponse(Object obj){
        return getResponse().setData(obj);
    }

    public static RestResponse getSucResponse(String message,Object obj){
        RestResponse restResponse=getResponse();
        restResponse.setMessage(message);
        restResponse.setData(obj);
        return restResponse;
    }

    public static RestResponse getErrorResponse(String message){
        return buildResponse(DefaultStatusEnum.ERROR.getCode(),message);
    }

    private static RestResponse buildResponse(String message){
        RestResponse restResponse=new RestResponse();
        restResponse.setMessage(message);
        return restResponse;
    }

    public static RestResponse buildResponse(String status,String message){
        RestResponse restResponse=new RestResponse();
        restResponse.setStatus(status);
        restResponse.setMessage(message);
        return restResponse;
    }

    public static RestResponse buildResponse(String status,String message,Object data){
        RestResponse restResponse=new RestResponse();
        restResponse.setStatus(status);
        restResponse.setMessage(message);
        restResponse.setData(data);
        return restResponse;
    }

    private static RestResponse getResponse() {
        return new RestResponse();
    }
}
